/*
 *  Gurr - A multiprotocol chat client for Android
 *  Copyright (C) 2011 Malte Aschermann, Wilfried Ramaker
 *  
 *  This file is part of Gurr.
 *  
 *  Gurr is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  Gurr is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *  
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Gurr.  If not, see <http://www.gnu.org/licenses/>.
 */




import java.io.IOException;
import java.util.HashMap;
import java.util.Map;


import ca.uwaterloo.crysp.otr.UserState;
import ca.uwaterloo.crysp.otr.crypt.Provider;
import ca.uwaterloo.crysp.otr.crypt.jca.JCAProvider;
import ca.uwaterloo.crysp.otr.iface.OTRCallbacks;
import ca.uwaterloo.crysp.otr.iface.OTRInterface;

public class OTRDriver {
	private static OTRDriver instance;

	public final static String fStrProtocolID_ICQ="prpl-oscar";
	
	private Map<String, Session> fMapUinSession;
	
	/** encapsulates the list of known fingerprints and the list of private keys */
	private OTRInterface fUsICQ;
	
	public String myName;
	/*public static OTRDriver getInstance() {
		if (instance == null)
			instance = new OTRDriver();
		return instance;
	}
	*/
	public OTRDriver(String name) {
		fMapUinSession = new HashMap<String, Session>();
		fUsICQ = new UserState(new JCAProvider());
		Provider p = new JCAProvider();
		myName = name;
	}
	
	public static OTRDriver d1;
	public static OTRDriver d2;
	
	
	public static void main(String[] args) {
		try {
			OTRInterface usICQd1 = new UserState(new JCAProvider());
			OTRInterface usICQd2 = new UserState(new JCAProvider());
			
			d1 = new OTRDriver("123");
			d1.startOTRSession("123", ProtocolType.ICQ, "456", usICQd1);
			d2 = new OTRDriver("456");
			d2.startOTRSession("456", ProtocolType.ICQ, "123", usICQd2);
			
			String dec = d1.getSession("456").send("test1323");
			
			System.out.println("hallo welt! -> " + dec);
			
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public Session startOTRSession(String pStrMyUin, ProtocolType pProtocol, String pStrRecipientUin, OTRInterface pUsICQ) throws IOException {
		
		Session s = new Session(pStrMyUin, pProtocol, pStrRecipientUin, pUsICQ);
		
		fMapUinSession.put(pStrRecipientUin, s);

		return s;
	}
	
	
	public boolean hasSession(String pStrRecipientUin) {
		if (fMapUinSession.containsKey(pStrRecipientUin))
			return true;
		else
			return false;
	}
	
	public Session getSession(String pStrRecipientUin) {
		return fMapUinSession.get(pStrRecipientUin);
	}

	protected OTRInterface getfUsICQ() {
		return fUsICQ;
	}
	
	
}



